import React, { useEffect, useRef, useState } from 'react'

function index(count=60) {
    const [num,setNum]=useState(count)
    const itmer=useRef(null)
    const [disdabled,setDisabled]=useState(false)

    const fn=()=>{
        setDisabled(true)
       itmer.current= setInterval(()=>{
            setNum((num)=>num-1)
        },1000)
    }
    useEffect(()=>{
        if(num===0){
            clearInterval(itmer.current)
            setNum(count)
            setDisabled(false)
        }
    },[num,count])
  return [num,fn,disdabled]
}

export default index
